package com.class05.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.concurrent.TimeUnit;

@Configuration
public class MVCConfig {

    /**
     * 配置静态资源处理器
     *
     * @return
     */
    @Bean
    public WebMvcConfigurer webMvcConfigurer() {
        return new WebMvcConfigurer() {
            @Override //配置静态资源
            public void addResourceHandlers(ResourceHandlerRegistry registry) {
//                addResourceHandler配置图片路径
                registry.addResourceHandler("/static/**")
//                        addResourceLocations配置静态资源路径，如html、css、js等
                        .addResourceLocations("classpath:/templates/", "classpath:/b/")
//                        设置缓存时间 1800秒
                        .setCacheControl(CacheControl.maxAge(1180, TimeUnit.SECONDS));
            }
        };
    }

//    @Bean



}
